#encoding:utf-8
'''
Created on 20/06/2012

@author: Ivanus
'''
from django.shortcuts import render_to_response
from salon.settings import CONFIGS
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.mail import EmailMessage

proyecto = ' | ' + CONFIGS['tituloProyecto']

def index(request):
    title = 'Home' + proyecto
    home = True
    return render_to_response('index.html', {'title': title, 'home': home}, context_instance = RequestContext(request))
    #return render_to_response('base/index.html', locals(), context_instance=RequestContext(request))

def paquetes(request):
    title = 'Nuestros paquetes' + proyecto
    paquet = True
    return render_to_response('paquetes.html', {'title': title, 'paquet': paquet}, context_instance = RequestContext(request))

def galeria(request):
    title = 'Galeria' + proyecto
    galery = True
    return render_to_response('galeria.html', {'title': title, 'galery': galery}, context_instance = RequestContext(request))

def contactenos(request):
    title = 'Contactenos' + proyecto
    contact = True
    if request.method == 'POST':
        destinatarioNombre = request.POST['nombre']
        asunto = CONFIGS['asuntoMail']
        mensaje = destinatarioNombre + " escribi�: \n\n" + request.POST['comentarios']
        victoriaEmail = CONFIGS['victoriaEmail']
        destinatarioEmail = request.POST['email']
        
        try:
            copia = request.POST['copia']
        except:
            copia = "off"
        
        #email = EmailMessage(asunto, mensaje, to=['Correo@correo.com'])
        
        if copia == "on" :
            email = EmailMessage(asunto, mensaje, to=[victoriaEmail, destinatarioEmail])
        else :
            email = EmailMessage(asunto, mensaje, to=[victoriaEmail])

        enviado = email.send()
        
        if enviado == 1 :
            home = True
            title = 'Home' + proyecto
            isEnviado = True
            return render_to_response('index.html', {'title': title, 'home': home, 'isEnviado': isEnviado}, context_instance = RequestContext(request))
        else :
            noEnviado = True
            return render_to_response('contactenos.html', {'title': title, 'contact': contact, 'noEnviado': noEnviado}, context_instance = RequestContext(request))
    
    return render_to_response('contactenos.html', {'title': title, 'contact': contact}, context_instance = RequestContext(request))

def components(request):
    title = 'Componentes' + proyecto
    return render_to_response('components.html', {'title': title}, context_instance = RequestContext(request))